package com.sumqun.mall.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.sumqun.mall.dao.AccountDao;

import com.sumqun.mall.entity.Account;
import com.sumqun.mall.mapper.AccountMapper;

@Repository
public class AccountDaoImpl implements AccountDao {

	@SuppressWarnings("unused")
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	private AccountMapper accountMapper;

	@Override
	public List findAllAccount(int offset, int pageSize) {
		Map map = new HashMap();
		map.put("offset", offset);
		map.put("pageSize", pageSize);
		return accountMapper.findAllAccount(map);
	}

	public int findAllCount() {
		Map map = new HashMap();		 
		return accountMapper.findAllCount(map);
	}

	public AccountMapper getAccountMapper() {
		return accountMapper;
	}

	public void setAccountMapper(AccountMapper accountMapper) {
		this.accountMapper = accountMapper;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Account findLoginUser(String username, String password,
			String usertype) {
		Map map = new HashMap();
		map.put("username", username);
		map.put("password", password);
		map.put("usertype", usertype);
		return accountMapper.verify(map);
	}

	@Override
	public Account findAccountById(int uid) {
		return accountMapper.findAccountById(uid);
	}

	@Override
	public void addAccount(Account account) {

		accountMapper.addAccount(account);
	}

	@Override
	public void editAccount(Account account) {
		accountMapper.editAccount(account);

	}

	@Override
	public void removeAccount(int uid) {
		accountMapper.removeAccount(uid);

	}

}
